package com.watch.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.watch.system.common.result.PageResult;
import com.watch.system.common.result.Result;
import com.watch.system.model.form.SysDescForm;
import com.watch.system.model.form.UserForm;
import com.watch.system.model.query.CarSysDescPageQuery;
import com.watch.system.model.query.CarUserPageQuery;
import com.watch.system.model.vo.CarSysDescPageVO;
import com.watch.system.model.vo.CarUserPageVO;
import com.watch.system.service.CarSysDescService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 *
 *模板编辑
 * @author gmli
 * @since 2024/1/29
 */
@Tag(name = "10.中车会系统模板编辑")
@RestController
@RequestMapping("/api/car/template")
@RequiredArgsConstructor
public class CarSysDescController {

    private final CarSysDescService carSysDescService;

    @Operation(summary = "用户分页列表")
    @GetMapping("/page")
    public PageResult<CarSysDescPageVO> getSysDescPage(@ParameterObject CarSysDescPageQuery queryParams) {
        IPage<CarSysDescPageVO> result = carSysDescService.getSysDescPage(queryParams);
        return PageResult.success(result);
    }


    @Operation(summary = "修改模板用户")
    @PutMapping(value = "/saveSysDesc")
     public Result saveSysDesc(@RequestBody @Validated SysDescForm sysDescForm) {
        // 查询文本类型
        if("20000".equals(sysDescForm.getType())){
            //查询type 类型

            Integer count =  carSysDescService.getSysDescInfo();
            sysDescForm.setType(count+"");
        }
        boolean result = carSysDescService.saveSysDesc(sysDescForm.getSysDescId(), sysDescForm);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("/{ids}")
    public Result deleteSysDesc(@Parameter(description = "用户ID，多个以英文逗号(,)分割") @PathVariable String ids) {
        boolean result = carSysDescService.deleteSysDesc(ids);
        return Result.judge(result);
    }


}
